package com.tanhua.server.controller;

import com.tanhua.model.vo.SoundVo;
import com.tanhua.server.service.PeachBlossomServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 桃花传音 控制层
 */
@Slf4j
@RestController
@RequestMapping("/peachblossom")
public class PeachBlossomController {

    @Autowired
    private PeachBlossomServer peachBlossomServer;

    /**
     * 桃花传音-接收语音（学生实战）从MongoDB取一条语音
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity getSound(){
        SoundVo soundVo = peachBlossomServer.getSound();
        return ResponseEntity.ok(soundVo);
    }

    /**
     * 桃花传音-发送语音（学生实战） 存一条语音到MongoDB
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity saveSound(@RequestBody MultipartFile soundFile){
        peachBlossomServer.saveSound(soundFile);
        return ResponseEntity.ok(null);
    }


}

